home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
stdio
/
c
/
fwrite
< prev
next >
Wrap
Text File
|
1996-11-09
|
1KB
|
66 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/fwrite,v $
* $Date: 1996/05/06 09:01:34 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: fwrite,v $
* Revision 1.2 1996/05/06 09:01:34 unixlib
* Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
* Saved for 3.7a release.
*
* Revision 1.1 1996/04/19 21:32:42 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: fwrite,v 1.2 1996/05/06 09:01:34 unixlib Rel $";
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
__STDIOLIB__
int
__fwrite (register FILE * f, register char *s, register int _n)
{
register int n, i, b, g = f->flag;
if ((g & (_IOWRITE | _IOERR | _IOEOF)) != _IOWRITE)
return (-1);
b = (g & _IONBF) ? 1 : f->bufsiz;
n = _n;
while (n)
{
if (i = ((n > f->o_cnt) ? f->o_cnt : n)) /* write buffer */
{
memcpy (f->o_ptr, s, i);
f->o_cnt -= i, f->o_ptr += i;
n -= i, s += i;
}
if (n || ((g & _IOLBF) && i && s[-1] == '\n'))
{
if (__flsbuf (-1, f) < 0) /* flush buffer */
return (_n - n);
}
while (n >= b) /* direct write() */
{
if ((i = write (f->fd, s, n - (n % b))) < b)
{
f->flag |= _IOERR;
return (_n - n + i);
}
f->pos += i, n -= i, s += i;
}
}
return (_n);
}